package prison.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shwread.android.qysw10000000.R;

/**
 * Created by lex on 2017/3/13.
 */

public class InServiceAdapter extends BaseAdapter {

    private Activity context;
    private Integer[] list;
    private String[] nlist;

    public InServiceAdapter(Activity context, String[] nlist, Integer[] list) {
        this.context = context;
        this.nlist = nlist;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.length;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        InServiceHolder holder = null;
        if (holder == null) {
            holder = new InServiceHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_in_service_grid, null);
            holder.iVInServiceItemIcon = (ImageView) view.findViewById(R.id.iVInServiceItemIcon);
            holder.tVInServiceItemName = (TextView) view.findViewById(R.id.tVInServiceItemName);
            view.setTag(holder);
        } else {
            holder = (InServiceHolder) view.getTag();
        }

        holder.tVInServiceItemName.setText(nlist[position]);
        holder.iVInServiceItemIcon.setImageResource(list[position]);
        return view;
    }

    class InServiceHolder {
        TextView tVInServiceItemName;
        ImageView iVInServiceItemIcon;
    }

}
